//
//  SignSuccessViewController.m
//  xingfugangwan
//
//  Created by rainday on 15/1/1.
//  Copyright (c) 2015年 rainday. All rights reserved.
//

#import "SignSuccessViewController.h"
#import "UMSCashierPlugin.h"


@interface SignSuccessViewController ()<UMSCashierPluginDelegate>{
    NSString *_payStyle;
    NSString *_price;
    NSString *_orderid;
    NSString *_umsOrerId;
    
    

}
@property (nonatomic ,weak) IBOutlet UIButton *payButton;
@property (nonatomic ,weak) IBOutlet UILabel *orderIdLabel;
@property (nonatomic ,weak) IBOutlet UILabel *priceLabel;
@property (nonatomic ,weak) IBOutlet UILabel *advanceLabel;


- (IBAction)didClickPayButton:(id)sender;


@end

@implementation SignSuccessViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil orderid:(NSString *)orderid price:(NSString *)price payStyle:(NSString *)payStyle
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        _orderid = orderid;
        _price = price;
        _payStyle = payStyle;
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _orderIdLabel.text = [NSString stringWithFormat:@"订单号:%@",_orderid];
    _priceLabel.text = [NSString stringWithFormat:@"全款金额:￥%@",_price];
    
    [_payButton setTitle:_payStyle forState:UIControlStateNormal];
    _payButton.layer.cornerRadius = 5;
    _payButton.layer.masksToBounds = YES;
    _advanceLabel.text = [NSString stringWithFormat:@"预付金额:￥%@",_advanceString];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


- (void)didClickPayButton:(id)sender
{
    UIButton *button = (UIButton *)sender;
    NSString *title = [button titleForState:UIControlStateNormal];
    if ([title isEqualToString:@"现金支付"]) {
        [_delegate SignSuccessViewController:self didPayPrice:@""];
        return;
    }
    
    //此处POS支付
  
    [UMSCashierPlugin bookOrder:@"1" MerorderId:@"898140172990227" MerOrderDesc:@"" BillsMID:@"898140172990227" BillsTID:@"72990145" operator:@"" Delegate:self ProductModel:NO];
    
    
    
}

- (void)onUMSBookOrderResult:(NSDictionary *)dict{
    if ([[dict objectForKey:@"resultStatus"] isEqualToString:@"success"]) {
        _umsOrerId = [dict objectForKey:@"orderId"];
        [UMSCashierPlugin setupDevice:@"001584056912078" BillsTID:@"20780003" WithViewController:self Delegate:self ProductModel:NO];
    }
    
}

- (void)onUMSSetupDevice:(BOOL)resultStatus resultInfo:(NSString *)resultInfo withDeviceId:(NSString *)deviceId{
    [UMSCashierPlugin payOrder:_umsOrerId BillsMID:@"001584056912078" BillsTID:@"20780003" WithViewController:self Delegate:self SalesSlipType:SalesSlipType_AUTO PayType:PayType_EPOS ProductModel:NO];
    
}
-(void)onPayResult:(PayStatus) payStatus PrintStatus:(PrintStatus) printStatus withInfo:(NSDictionary *)dict{
    //    PayStatus_PAYSUCCESS,              //交易成功
    //    PayStatus_PAYFAIL,                 //交易失败
    //    PayStatus_PAYTIMEOUT,              //交易超时
    //    PayStatus_PAYCANCEL,               //交易取消
    //
    //    PayStatus_VOIDSUCCESS,              //撤销成功
    //    PayStatus_VOIDFAIL,                 //撤销失败
    //    PayStatus_VOIDTIMEOUT,              //撤销超时
    //    PayStatus_VOIDCANCEL
    
    switch (payStatus) {
        case PayStatus_PAYFAIL:
            
            break;
        case PayStatus_PAYCANCEL:
            break;
        case PayStatus_PAYSUCCESS:
            
            [self dismissViewControllerAnimated:YES completion:nil];
            return;
            break;
        default:
            break;
    }
}


@end
